package com.epam.training.domain;

import java.io.Serializable;

import javax.persistence.*;
import javax.validation.constraints.Future;

import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * The persistent class for the bookingitem database table.
 * 
 */
@Entity
@Table(name = "bookingitem")
@NamedQuery(name = "BookingItem.findAll", query = "SELECT b FROM BookingItem b")
public class BookingItem implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name = "BOOKINGITEM_BOOKINGID_GENERATOR", sequenceName = "bookinkitem_id_seq", initialValue = 1, allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BOOKINGITEM_BOOKINGID_GENERATOR")
	@Column(name = "booking_id", insertable = false, updatable = false, unique = true, nullable = false)
	private Integer bookingId;

	@Temporal(TemporalType.DATE)
	private Date date;

	@Column(name = "date_of_issue")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
	@Future
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateOfIssue;

	@Column(name = "date_of_return")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
	@Future
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateOfReturn;

	@Column(name = "place_of_issue", length = 120)
	private String placeOfIssue;

	@Column(name = "place_of_return", length = 120)
	private String placeOfReturn;

	@Column(length = 10)
	private String serial;

	@Column(length = 7)
	private String status;

	// bi-directional many-to-one association to Car
	@ManyToOne
	@JoinColumn(name = "car_id", nullable = false)
	private Car car;

	// bi-directional many-to-one association to Customer
	@ManyToOne
	@JoinColumn(name = "customer_id", nullable = false)
	private Customer customer;

	// bi-directional many-to-one association to Insurance
	@ManyToOne
	@JoinColumn(name = "insurance_id", nullable = false)
	private Insurance insurance;

	// bi-directional many-to-one association to Paymant
	@OneToOne
	@JoinColumn(name = "paymant_id")
	private Paymant paymant;

	public BookingItem() {
	}

	public Integer getBookingId() {
		return this.bookingId;
	}

	public void setBookingId(Integer bookingId) {
		this.bookingId = bookingId;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Date getDateOfIssue() {
		return this.dateOfIssue;
	}

	public void setDateOfIssue(Date dateOfIssue) {
		this.dateOfIssue = dateOfIssue;
	}

	public Date getDateOfReturn() {
		return this.dateOfReturn;
	}

	public void setDateOfReturn(Date dateOfReturn) {
		this.dateOfReturn = dateOfReturn;
	}

	public String getPlaceOfIssue() {
		return this.placeOfIssue;
	}

	public void setPlaceOfIssue(String placeOfIssue) {
		this.placeOfIssue = placeOfIssue;
	}

	public String getPlaceOfReturn() {
		return this.placeOfReturn;
	}

	public void setPlaceOfReturn(String placeOfReturn) {
		this.placeOfReturn = placeOfReturn;
	}

	public String getSerial() {
		return this.serial;
	}

	public void setSerial(String serial) {
		this.serial = serial;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Car getCar() {
		return this.car;
	}

	public void setCar(Car car) {
		this.car = car;
	}

	public Customer getCustomer() {
		return this.customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Insurance getInsurance() {
		return this.insurance;
	}

	public void setInsurance(Insurance insurance) {
		this.insurance = insurance;
	}

	public Paymant getPaymant() {
		return this.paymant;
	}

	public void setPaymant(Paymant paymant) {
		this.paymant = paymant;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((bookingId == null) ? 0 : bookingId.hashCode());
		result = prime * result + ((car == null) ? 0 : car.hashCode());
		result = prime * result
				+ ((customer == null) ? 0 : customer.hashCode());
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result
				+ ((dateOfIssue == null) ? 0 : dateOfIssue.hashCode());
		result = prime * result
				+ ((dateOfReturn == null) ? 0 : dateOfReturn.hashCode());
		result = prime * result
				+ ((insurance == null) ? 0 : insurance.hashCode());
		result = prime * result + ((paymant == null) ? 0 : paymant.hashCode());
		result = prime * result
				+ ((placeOfIssue == null) ? 0 : placeOfIssue.hashCode());
		result = prime * result
				+ ((placeOfReturn == null) ? 0 : placeOfReturn.hashCode());
		result = prime * result + ((serial == null) ? 0 : serial.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BookingItem other = (BookingItem) obj;
		if (bookingId == null) {
			if (other.bookingId != null)
				return false;
		} else if (!bookingId.equals(other.bookingId))
			return false;
		if (car == null) {
			if (other.car != null)
				return false;
		} else if (!car.equals(other.car))
			return false;
		if (customer == null) {
			if (other.customer != null)
				return false;
		} else if (!customer.equals(other.customer))
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (dateOfIssue == null) {
			if (other.dateOfIssue != null)
				return false;
		} else if (!dateOfIssue.equals(other.dateOfIssue))
			return false;
		if (dateOfReturn == null) {
			if (other.dateOfReturn != null)
				return false;
		} else if (!dateOfReturn.equals(other.dateOfReturn))
			return false;
		if (insurance == null) {
			if (other.insurance != null)
				return false;
		} else if (!insurance.equals(other.insurance))
			return false;
		if (paymant == null) {
			if (other.paymant != null)
				return false;
		} else if (!paymant.equals(other.paymant))
			return false;
		if (placeOfIssue == null) {
			if (other.placeOfIssue != null)
				return false;
		} else if (!placeOfIssue.equals(other.placeOfIssue))
			return false;
		if (placeOfReturn == null) {
			if (other.placeOfReturn != null)
				return false;
		} else if (!placeOfReturn.equals(other.placeOfReturn))
			return false;
		if (serial == null) {
			if (other.serial != null)
				return false;
		} else if (!serial.equals(other.serial))
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		return true;
	}
}
